import java.util.*;

public class Test2 {
    public static void main(String[] args) {
        LinkedList<Integer> linkedList1 = new LinkedList<>();
        List<Integer> linkedList2 = new LinkedList<>();
        linkedList1.add(1);
        linkedList1.add(2);
        linkedList1.add(3);
        System.out.println(linkedList1);

        System.out.println("=====for each========");
        //冒号右边是遍历的对象
        for (Integer x:linkedList1){
            System.out.print(x + " ");
        }
        System.out.println();
        System.out.println("=====for========");
        for (int i = 0; i < linkedList1.size(); i++) {
            System.out.print(linkedList1.get(i)+ " ");

        }
        System.out.println();


        System.out.println("=====  Iterator   ========");
        //iterator 可以获取一个迭代器对象
        linkedList1.iterator();
        Iterator<Integer> it = linkedList1.iterator();
        while(it.hasNext()){//判断有没有下一个
            System.out.print(it.next()+ " ");//打印出来同时向后走一步
        }
        System.out.println();

        //ListIterator是Iterator的子类,一般打印list相关的
        System.out.println("=====  ListIterator   ========");
        ListIterator<Integer> listIterator = linkedList1.listIterator();
        while(listIterator.hasNext()){//判断有没有下一个
            System.out.print(listIterator.next()+ " ");//打印出来同时向后走一步
        }
        System.out.println();


        System.out.println("=====  ListIterator   ========");
        ListIterator<Integer> listIterator1 = linkedList1.listIterator(1);//在指定位置开始打印
        while(listIterator1.hasNext()){//判断有没有下一个
            System.out.print(listIterator1.next()+ " ");//打印出来同时向后走一步
        }
        System.out.println();

        System.out.println("=====  ListIterator   ========");
        ListIterator<Integer> listIterator2 = linkedList1.listIterator(linkedList1.size()-1);//在指定位置开始打印
        while(listIterator2.hasNext()){//判断有没有下一个
            System.out.print(listIterator2.next()+ " ");//打印出来同时向后走一步
        }
        System.out.println();


        System.out.println("=====  ListIterator   ========");
        ListIterator<Integer> listIterator3 = linkedList1.listIterator(linkedList1.size());//在指定位置开始打印
        while(listIterator3.hasPrevious()){//判断有没有前一个
            System.out.print(listIterator3.previous()+ " ");//打印出来同时向前走一步
        }
        System.out.println();
    }
    public static void main1(String[] args) {
        LinkedList<Integer> linkedList1 = new LinkedList<>();
        List<Integer> linkedList2 = new LinkedList<>();
        linkedList1.add(1);
        linkedList1.addFirst(2);
        System.out.println(linkedList1);

        ArrayList<Integer> list = new ArrayList<>();
        list.add(11);
        list.add(22);
        list.add(222);
        linkedList1.addAll(list);
        System.out.println(linkedList1);
        linkedList1.remove(1);
        System.out.println(linkedList1);




    }
}
